#ifndef _T_EVENT_H_
#define _T_EVENT_H_
#include "fd/delegate.hpp"
#include "threadlock.h"


namespace libutils
{
	//comment this is 
	template<typename  TData, class mt_policy = threadlock::multi_threaded_local>
	class  TEvent
	{
	public:
		typedef	fd::delegate2<void,void*,const TData&> OnDataDel;

		TEvent(OnDataDel del)
		{
			threadlock::autoguard<mt_policy> guard(&m_policy); 
			m_eventdel += del;
			//return *this;

		}

		TEvent()
		{
		
		}


		TEvent& operator += (OnDataDel right)
		{
			threadlock::autoguard<mt_policy> guard(&m_policy); 
			m_eventdel += right;
			return *this;
		}

		TEvent& operator -= (OnDataDel right)
		{
			threadlock::autoguard<mt_policy> guard(&m_policy); 
			m_eventdel -= right;
			return *this;
		}
		void operator() (void* p,const TData& d)
		{
			threadlock::autoguard<mt_policy> guard(&m_policy); 
			m_eventdel(p,d);
		}

	private:
		OnDataDel m_eventdel;
		mt_policy m_policy;
	};


};
#endif